<template>
  <div id="app">
    <Head :deviceList="deviceList" />
    <CurrentStatus :device="device" />
    <DetailData :device="device" />
    <div id="container"></div>
  </div>
</template>

<script>
import Head from "./components/Head.vue";
import CurrentStatus from "./components/CurrentStatus.vue";
import { Line } from "@antv/g2plot"; // 引入图表组件
import DetailData from "./components/DetailData";

export default {
  name: "App",
  components: {
    Head,
    CurrentStatus,
    DetailData
  },
  data() {
    return {
      deviceList: [], // 设备列表
      device: {} // 当前选中的设备
    };
  },
  created() {
    this.$http.get("/v1/deviceInfo/list").then(res => {
      this.deviceList = res.data;
      this.device = this.deviceList[0];
    });
  },
  mounted() {
    const data = [
      { year: "1991", value: 3 },
      { year: "1992", value: 4 },
      { year: "1993", value: 3.5 },
      { year: "1994", value: 5 },
      { year: "1995", value: 4.9 },
      { year: "1996", value: 6 },
      { year: "1997", value: 7 },
      { year: "1998", value: 9 },
      { year: "1999", value: 13 }
    ];

    const line = new Line("container", {
      data,
      xField: "year",
      yField: "value"
    });

    line.render();
  }
};
</script>

<style>
body {
  padding: 0;
  margin: 0;
}
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
</style>
